import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
import type { BaseinfoDemandApi } from '#/api/csyt/baseinfodemand';

import { DICT_TYPE, getDictOptions } from '#/utils';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'demandName',
      label: '需求名称',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入需求名称',
      },
    },
    {
      fieldName: 'demandNo',
      label: '需求编码',
      rules: 'required',
      component: 'Input',
      componentProps: {
        onChange(e: any) {
          console.warn('onChange', e);
        },
        placeholder: '请输入需求编码',
      },
    },
    {
      fieldName: 'companyName',
      label: '企业名称',
      component: 'Input',
      componentProps: {
        placeholder: '请输入企业名称',
      },
    },
    {
      fieldName: 'priceInterval',
      label: '价格区间',
      component: 'Input',
      componentProps: {
        placeholder: '请输入价格区间',
      },
    },
    {
      fieldName: 'sector',
      label: '所属行业',
      component: 'Select',
      componentProps: {
        cleanOptions: true,
        options: getDictOptions(DICT_TYPE.CSYT_BASEINFO_COMPANY_TYPE),
        placeholder: '请选择所属行业',
      },
    },
    {
      fieldName: 'dateEnd',
      label: '截止时间',
      component: 'Input',
      componentProps: {
        placeholder: '请输入截止时间',
      },
    },
    {
      fieldName: 'customerType',
      label: '服务客群',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_TYPE.CSYT_BASEINFO_CUSTOMER_TYPE),
        placeholder: '请选择服务客群',
      },
    },
    {
      fieldName: 'serviceDescription',
      label: '服务描述',
      component: 'Textarea',
      componentProps: {
        placeholder: '请输入服务描述',
      },
    },
    {
      fieldName: 'serviceType',
      label: '产品服务',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_TYPE.CSYT_BASEINFO_SERVICE_TYPE),
        placeholder: '请选择产品服务',
      },
    },
    {
      fieldName: 'demandDescription',
      label: '需求描述',
      component: 'Textarea',
      componentProps: {
        placeholder: '请输入需求描述',
      },
    },
    {
      fieldName: 'modelingType',
      label: '建模名称',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_TYPE.CSYT_BASEINFO_MODELING_TYPE),
        placeholder: '请选择建模名称',
      },
    },
    {
      fieldName: 'modelingDescription',
      label: '建模描述',
      component: 'Textarea',
      componentProps: {
        placeholder: '请输入建模描述',
      },
    },
    {
      fieldName: 'processType',
      label: '流程名称',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_TYPE.CSYT_BASEINFO_PROCESS_TYPE),
        placeholder: '请选择流程名称',
      },
    },
    {
      fieldName: 'processDescription',
      label: '流程描述',
      component: 'Textarea',
      componentProps: {
        placeholder: '请输入流程描述',
      },
    },
    {
      fieldName: 'demandStatus',
      label: '需求状态',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_TYPE.CSYT_BASEINFO_PRODUCT_STATUS),
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'phone',
      label: '联系电话',
      component: 'Input',
      componentProps: {
        placeholder: '请输入联系电话',
      },
    },
  ];
}

/** 新增/修改的表单 */
export function demandeStatusFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'demandName',
      label: '需求名称',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入需求名称',
      },
    },
    {
      fieldName: 'demandNo',
      label: '需求编码',
      rules: 'required',
      component: 'Input',
      componentProps: {
        onChange(e: any) {
          console.warn('onChange', e);
        },
        placeholder: '请输入需求编码',
      },
    },
    {
      fieldName: 'companyName',
      label: '企业名称',
      component: 'Input',
      componentProps: {
        placeholder: '请输入企业名称',
      },
    },
    {
      fieldName: 'demandStatus',
      label: '需求状态',
      component: 'Select',
      componentProps: {
        placeholder: '请输入企业名称',
        options: getDictOptions(DICT_TYPE.CSYT_BASEINFO_PRODUCT_STATUS),
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'demandName',
      label: '需求名称',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入需求名称',
      },
    },
    {
      fieldName: 'demandNo',
      label: '需求编码',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入需求编码',
      },
    },
    {
      fieldName: 'demandStatus',
      label: '需求状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_TYPE.CSYT_BASEINFO_PRODUCT_STATUS),
        placeholder: '请选择需求状态',
      },
    },
    {
      fieldName: 'phone',
      label: '联系电话',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入联系电话',
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<BaseinfoDemandApi.BaseinfoDemand>['columns'] {
  return [
    { type: 'checkbox', width: 40 },
    {
      field: 'id',
      title: '序号',
      minWidth: 120,
    },
    {
      field: 'demandName',
      title: '需求名称',
      minWidth: 120,
    },
    {
      field: 'demandNo',
      title: '需求编码',
      minWidth: 120,
    },
    {
      field: 'companyName',
      title: '企业名称',
      minWidth: 120,
    },
    {
      field: 'priceInterval',
      title: '价格区间',
      minWidth: 120,
    },
    {
      field: 'dateEnd',
      title: '截止时间',
      minWidth: 120,
    },
    {
      field: 'sector',
      title: '所属行业',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: {
          type: DICT_TYPE.CSYT_BASEINFO_COMPANY_TYPE,
        },
      },
    },
    {
      field: 'serviceType',
      title: '产品服务',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: {
          type: DICT_TYPE.CSYT_BASEINFO_SERVICE_TYPE,
        },
      },
    },
    {
      field: 'customerType',
      title: '服务客群',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: {
          type: DICT_TYPE.CSYT_BASEINFO_CUSTOMER_TYPE,
        },
      },
    },
    {
      field: 'serviceDescription',
      title: '服务描述',
      minWidth: 120,
    },
    {
      field: 'demandDescription',
      title: '需求描述',
      minWidth: 120,
    },
    {
      field: 'modelingType',
      title: '建模名称',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: {
          type: DICT_TYPE.CSYT_BASEINFO_MODELING_TYPE,
        },
      },
    },
    {
      field: 'modelingDescription',
      title: '建模描述',
      minWidth: 120,
    },
    {
      field: 'processType',
      title: '流程名称',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: {
          type: DICT_TYPE.CSYT_BASEINFO_PROCESS_TYPE,
        },
      },
    },
    {
      field: 'processDescription',
      title: '流程描述',
      minWidth: 120,
    },
    {
      field: 'demandStatus',
      title: '需求状态',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: {
          type: DICT_TYPE.CSYT_BASEINFO_PRODUCT_STATUS,
        },
      },
    },
    {
      field: 'phone',
      title: '联系电话',
      minWidth: 120,
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
  ];
}

// ==================== 子表（需求指标） ====================

/** 新增/修改列表的字段 */
export function useBaseinfoIndicatorGridEditColumns(
  onActionClick?: OnActionClickFn<BaseinfoDemandApi.BaseinfoIndicator>,
): VxeTableGridOptions<BaseinfoDemandApi.BaseinfoIndicator>['columns'] {
  return [
    {
      field: 'id',
      title: '序号',
      minWidth: 60,
      slots: { default: 'id' },
    },
    {
      field: 'ruleName',
      title: '规则名称',
      minWidth: 120,
      slots: { default: 'ruleName' },
    },
    {
      field: 'ruleDescription',
      title: '规则描述',
      minWidth: 120,
      slots: { default: 'ruleDescription' },
    },
    {
      field: 'targetNo',
      title: '指标编码',
      minWidth: 120,
      slots: { default: 'targetNo' },
    },
    {
      field: 'targetName',
      title: '指标名称',
      minWidth: 120,
      slots: { default: 'targetName' },
    },
    {
      field: 'targetDescription',
      title: '指标描述',
      minWidth: 120,
      slots: { default: 'targetDescription' },
    },
    {
      field: 'operation',
      title: '操作',
      minWidth: 180,
      align: 'center',
      fixed: 'right',
      showOverflow: false,
      cellRender: {
        attrs: {
          nameField: 'id',
          nameTitle: '指标',
          onClick: onActionClick,
        },
        name: 'CellOperation',
        options: [
          {
            code: 'delete',
            show: true,
          },
        ],
      },
    },
  ];
}
